﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using JKF.DataModule.IDAL;
using JKF.Substructure;//请先添加引用

namespace JKF.DataModule.SqlServerDAL
{
    public partial class dalSMS_ACCOUNT : IdalSMS_ACCOUNT
    {
        private const string FieldShow = "SHOP_CODE,SHOP_NAME,LINKMAN,isnull(SMS_ACCOUNT,'') SMS_ACCOUNT,[SMS_PWD],isnull(AMOUNT,0) AMOUNT,isnull(NUM_SENDED,0) NUM_SENDED,isnull(NUM_LEFT,0) NUM_LEFT,isnull(SIGNATURE,'') SIGNATURE,isnull(STATUS,'0') STATUS, convert(char(10), DATE_CREATE,120) DATE_CREATE";
        private const string FieldOrder = "DATE_CREATE";
        private const string FieldKey = "ID";

        public DataTable GetSMSAccounts(string searchItem, string matchWay, string keyword, 
         int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            var sql = new StringBuilder(@"  1=1 ");
            if (!string.IsNullOrEmpty(searchItem) && !string.IsNullOrEmpty(keyword))
            {
                if (matchWay == "包含")
                {
                    sql.AppendFormat(" AND {0} LIKE '%{1}%' ", searchItem, keyword);
                }
                else
                {
                    sql.AppendFormat(" AND {0} = '{1}' ", searchItem, keyword);
                }
            }
            return DataPage.GetPageInfo("V_SMS_ACCOUNT", FieldKey, pageCurrent, pageSize, FieldShow, FieldOrder, sql.ToString(), ref pageCount, ref rowCount).Tables[0];
        }
    }
}
